package cn.picclife.mwx.common.core.util.redis;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

@Service
public class CashValueCache{
	private final String KEY_PREFIX="User:";
	
	@Resource(name = "redisUtil")
	RedisUtil redisUtil;
	
	public void saveCashValue(String product_id,Integer period,Double amount,List<String> cashValues){
		String key = createCacheKey(product_id,period,amount);
		redisUtil.setObject(key, cashValues);
	}
	
	@SuppressWarnings("unchecked")
	public List<String> getCashValues(String product_id,Integer period,Double amount){
		String key = createCacheKey(product_id,period,amount);
		
		return (List<String>)redisUtil.getObject(key,List.class);
	}
	
	private String createCacheKey(String product_id,Integer period,Double amount){
		StringBuilder key = new StringBuilder(KEY_PREFIX);
		key.append(product_id).append("|").append("|").append("|").append(period).append("|").append("|").append(amount);
		return key.toString();
	}
}
